package com.cn.distributor.service.Impl;



import com.cn.common.result.Result;
import com.cn.distributor.entity.Enterprise;
import com.cn.distributor.entity.Personal;
import com.cn.distributor.mapper.AuditingMapper;
import com.cn.distributor.service.AuditingService;
import com.cn.distributor.vo.AuditingVo;
import com.cn.distributor.vo.DistributorIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.soap.Text;
import java.util.List;


@Service("AuditingService")
public class AuditingServiceImpl implements AuditingService {

    @Autowired
    private AuditingMapper auditingMapper;
    @Override
    public Result findEnterprise(Enterprise enterprise) {

        List<Enterprise> enterpriseList = auditingMapper.findEnterprise(enterprise);

        return Result.success(enterpriseList);
    }

    @Override
    public Result findPersonal(Personal personal) {
        List<Personal> personalList = auditingMapper.findPersonal(personal);

        return Result.success(personalList);
    }

    @Override
    public Result auditSuccessful(DistributorIdVo distributorIdVo) {
        int a = auditingMapper.getVersion(distributorIdVo);
        long count = auditingMapper.auditSuccessful(distributorIdVo,a);
        if (count == 1)
        {
            auditingMapper.addShop();
           AuditingVo auditing = auditingMapper.findByDistributor(distributorIdVo);
           if (auditing.getType() == 1)
           {
               Enterprise enterprise = auditingMapper.findByIdEnterPrise(distributorIdVo);
               auditingMapper.addEnterPrise(enterprise);
           }
            Personal personal = auditingMapper.findByIdPersonal(distributorIdVo);
            auditingMapper.addPersonal(personal);

            return Result.success(count);
        }
        return null;
    }

    @Override
    public Result rejectionReview(DistributorIdVo distributorIdVo, Text text) {

        long count = auditingMapper.rejectionReview(distributorIdVo,text);

        return Result.success(count);
    }
}
